1. Project Clover database Sat Apr 27 2024 21:29:13 CDT
  2. Package net.bytebuddy.matcher

File ElementMatchers.java

 

Coverage histogram

../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

18
179
158
1
1,878
551
169
0.94
1.13
158
1.07

Classes

Class Line # Actions
ElementMatchers 35 179 0% 169 1
0.997183199.7%
 

Contributing tests

This file is covered by 2196 tests. .

Source view

1    package net.bytebuddy.matcher;
2   
3    import net.bytebuddy.description.ByteCodeElement;
4    import net.bytebuddy.description.ModifierReviewable;
5    import net.bytebuddy.description.NamedElement;
6    import net.bytebuddy.description.annotation.AnnotatedCodeElement;
7    import net.bytebuddy.description.annotation.AnnotationDescription;
8    import net.bytebuddy.description.annotation.AnnotationList;
9    import net.bytebuddy.description.field.FieldDescription;
10    import net.bytebuddy.description.field.FieldList;
11    import net.bytebuddy.description.method.MethodDescription;
12    import net.bytebuddy.description.method.MethodList;
13    import net.bytebuddy.description.method.ParameterDescription;
14    import net.bytebuddy.description.method.ParameterList;
15    import net.bytebuddy.description.type.TypeDefinition;
16    import net.bytebuddy.description.type.TypeDescription;
17    import net.bytebuddy.description.type.TypeList;
18    import net.bytebuddy.utility.JavaModule;
19   
20    import java.lang.annotation.Annotation;
21    import java.lang.reflect.Constructor;
22    import java.lang.reflect.Field;
23    import java.lang.reflect.Method;
24    import java.lang.reflect.Type;
25    import java.util.ArrayList;
26    import java.util.Arrays;
27    import java.util.Collections;
28    import java.util.List;
29    import java.util.concurrent.ConcurrentHashMap;
30    import java.util.concurrent.ConcurrentMap;
31   
32    /**
33    * A utility class that contains a human-readable language for creating {@link net.bytebuddy.matcher.ElementMatcher}s.
34    */
 
35    public final class ElementMatchers {
36   
37    /**
38    * A readable reference to the bootstrap class loader which is represented by {@code null}.
39    */
40    private static final ClassLoader BOOTSTRAP_CLASSLOADER = null;
41   
42    /**
43    * A private constructor that must not be invoked.
44    */
 
45  1 toggle private ElementMatchers() {
46  1 throw new UnsupportedOperationException();
47    }
48   
49    /**
50    * Wraps another matcher to assure that an element is not matched in case that the matching causes an {@link Exception}.
51    *
52    * @param matcher The element matcher that potentially throws an exception.
53    * @param <T> The type of the matched object.
54    * @return A matcher that returns {@code false} in case that the given matcher throws an exception.
55    */
 
56  2 toggle public static <T> ElementMatcher.Junction<T> failSafe(ElementMatcher<? super T> matcher) {
57  2 return new FailSafeMatcher<T>(matcher, false);
58    }
59   
60    /**
61    * <p>
62    * Wraps another matcher but caches the result of previously matched elements. Caching can be important if a
63    * matcher requires expensive calculations.
64    * </p>
65    * <p>
66    * <b>Warning</b>: The supplied map can however introduce a memory leak as the matched elements are stored within the map.
67    * It is therefore important to dereference this matcher at some point or to regularly evict entries from the supplied map.
68    * </p>
69    *
70    * @param matcher The actual matcher for which the results are cached.
71    * @param map The map for storing results of previously matched elements.
72    * @param <T> The type of the matched object.
73    * @return A matcher that stores the results of a previous matching in the supplied map.
74    */
 
75  1 toggle public static <T> ElementMatcher.Junction<T> cached(ElementMatcher<? super T> matcher, ConcurrentMap<? super T, Boolean> map) {
76  1 return new CachingMatcher<T>(matcher, map);
77    }
78   
79    /**
80    * <p>
81    * Wraps another matcher but caches the result of previously matched elements. Caching can be important if a
82    * matcher requires expensive calculations.
83    * </p>
84    * <p>
85    * <b>Warning</b>: The cache will hold {@code evictionSize} elements and evict a random element once the cache
86    * contains more than the specified amount of elements. Cached elements are referenced strongly and might cause
87    * a memory leak if instance are of a significant size. Using {@link ElementMatchers#cached(ElementMatcher, ConcurrentMap)}
88    * allows for explicit control over cache eviction.
89    * </p>
90    *
91    * @param matcher The actual matcher for which the results are cached.
92    * @param evictionSize The maximum amount of elements that are stored in the cache. Must be a positive number.
93    * @param <T> The type of the matched object.
94    * @return A matcher that stores the results of a previous matching in the supplied map.
95    */
 
96  2 toggle public static <T> ElementMatcher.Junction<T> cached(ElementMatcher<? super T> matcher, int evictionSize) {
97  2 if (evictionSize < 1) {
98  1 throw new IllegalArgumentException("Eviction size must be a positive number: " + evictionSize);
99    }
100  1 return new CachingMatcher.WithInlineEviction<T>(matcher, new ConcurrentHashMap<T, Boolean>(), evictionSize);
101    }
102   
103    /**
104    * Matches the given value which can also be {@code null} by the {@link java.lang.Object#equals(Object)} method or
105    * by a null-check.
106    *
107    * @param value The value that is to be matched.
108    * @param <T> The type of the matched object.
109    * @return A matcher that matches an exact value.
110    */
 
111  23911 toggle public static <T> ElementMatcher.Junction<T> is(Object value) {
112  23911 return value == null
113    ? new NullMatcher<T>()
114    : new EqualityMatcher<T>(value);
115    }
116   
117    /**
118    * Exactly matches a given field as a {@link FieldDescription}.
119    *
120    * @param field The field to match by its description
121    * @param <T> The type of the matched object.
122    * @return An element matcher that exactly matches the given field.
123    */
 
124  243 toggle public static <T extends FieldDescription> ElementMatcher.Junction<T> is(Field field) {
125  243 return definedField(is(new FieldDescription.ForLoadedField(field)));
126    }
127   
128    /**
129    * Matches a field in its defined shape.
130    *
131    * @param matcher The matcher to apply to the matched field's defined shape.
132    * @param <T> The matched object's type.
133    * @return A matcher that matches a matched field's defined shape.
134    */
 
135  261 toggle public static <T extends FieldDescription> ElementMatcher.Junction<T> definedField(ElementMatcher<? super FieldDescription.InDefinedShape> matcher) {
136  261 return new DefinedShapeMatcher<T, FieldDescription.InDefinedShape>(matcher);
137    }
138   
139    /**
140    * Exactly matches a given method as a {@link MethodDescription}.
141    *
142    * @param method The method to match by its description
143    * @param <T> The type of the matched object.
144    * @return An element matcher that exactly matches the given method.
145    */
 
146  222 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> is(Method method) {
147  222 return definedMethod(is(new MethodDescription.ForLoadedMethod(method)));
148    }
149   
150    /**
151    * Exactly matches a given constructor as a {@link MethodDescription}.
152    *
153    * @param constructor The constructor to match by its description
154    * @param <T> The type of the matched object.
155    * @return An element matcher that exactly matches the given constructor.
156    */
 
157  108 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> is(Constructor<?> constructor) {
158  108 return definedMethod(is(new MethodDescription.ForLoadedConstructor(constructor)));
159    }
160   
161    /**
162    * Matches a method in its defined shape.
163    *
164    * @param matcher The matcher to apply to the matched method's defined shape.
165    * @param <T> The matched object's type.
166    * @return A matcher that matches a matched method's defined shape.
167    */
 
168  357 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> definedMethod(ElementMatcher<? super MethodDescription.InDefinedShape> matcher) {
169  357 return new DefinedShapeMatcher<T, MethodDescription.InDefinedShape>(matcher);
170    }
171   
172    /**
173    * Matches a parameter in its defined shape.
174    *
175    * @param matcher The matcher to apply to the matched parameter's defined shape.
176    * @param <T> The matched object's type.
177    * @return A matcher that matches a matched parameter's defined shape.
178    */
 
179  1 toggle public static <T extends ParameterDescription> ElementMatcher.Junction<T> definedParameter(ElementMatcher<? super ParameterDescription.InDefinedShape> matcher) {
180  1 return new DefinedShapeMatcher<T, ParameterDescription.InDefinedShape>(matcher);
181    }
182   
183    /**
184    * Matches a parameter's type by the given matcher.
185    *
186    * @param matcher The matcher to apply to the parameter's type.
187    * @param <T> The type of the matched object.
188    * @return A matcher that matches a parameter's type by the given matcher.
189    */
 
190  1476 toggle public static <T extends ParameterDescription> ElementMatcher.Junction<T> hasType(ElementMatcher<? super TypeDescription> matcher) {
191  1476 return hasGenericType(rawType(matcher));
192    }
193   
194    /**
195    * Matches a method parameter by its generic type.
196    *
197    * @param matcher The matcher to apply to a parameter's generic type.
198    * @param <T> The type of the matched object.
199    * @return A matcher that matches the matched parameter's generic type.
200    */
 
201  1476 toggle public static <T extends ParameterDescription> ElementMatcher.Junction<T> hasGenericType(ElementMatcher<? super TypeDescription.Generic> matcher) {
202  1476 return new MethodParameterTypeMatcher<T>(matcher);
203    }
204   
205    /**
206    * Exactly matches a given type as a {@link TypeDescription}.
207    *
208    * @param type The type to match by its description
209    * @param <T> The type of the matched object.
210    * @return An element matcher that exactly matches the given type.
211    */
 
212  487 toggle public static <T extends TypeDefinition> ElementMatcher.Junction<T> is(Type type) {
213  487 return is(TypeDefinition.Sort.describe(type));
214    }
215   
216    /**
217    * Exactly matches a given annotation as an {@link AnnotationDescription}.
218    *
219    * @param annotation The annotation to match by its description.
220    * @param <T> The type of the matched object.
221    * @return An element matcher that exactly matches the given annotation.
222    */
 
223  2 toggle public static <T extends AnnotationDescription> ElementMatcher.Junction<T> is(Annotation annotation) {
224  2 return is(AnnotationDescription.ForLoadedAnnotation.of(annotation));
225    }
226   
227    /**
228    * Inverts another matcher.
229    *
230    * @param matcher The matcher to invert.
231    * @param <T> The type of the matched object.
232    * @return An inverted version of the given {@code matcher}.
233    */
 
234  17463 toggle public static <T> ElementMatcher.Junction<T> not(ElementMatcher<? super T> matcher) {
235  17463 return new NegatingMatcher<T>(matcher);
236    }
237   
238    /**
239    * Creates a matcher that always returns {@code true}.
240    *
241    * @param <T> The type of the matched object.
242    * @return A matcher that matches anything.
243    */
 
244  3164 toggle public static <T> ElementMatcher.Junction<T> any() {
245  3164 return new BooleanMatcher<T>(true);
246    }
247   
248    /**
249    * Creates a matcher that always returns {@code false}.
250    *
251    * @param <T> The type of the matched object.
252    * @return A matcher that matches nothing.
253    */
 
254  2509 toggle public static <T> ElementMatcher.Junction<T> none() {
255  2509 return new BooleanMatcher<T>(false);
256    }
257   
258    /**
259    * <p>
260    * Creates a matcher that matches any of the given objects by the {@link java.lang.Object#equals(Object)} method.
261    * None of the values must be {@code null}.
262    * </p>
263    * <p>
264    * <b>Important</b>: This method cannot be used interchangably with any of its overloaded versions which also apply a type
265    * conversion.
266    * </p>
267    *
268    * @param value The input values to be compared against.
269    * @param <T> The type of the matched object.
270    * @return A matcher that checks for the equality with any of the given objects.
271    */
 
272  18 toggle public static <T> ElementMatcher.Junction<T> anyOf(Object... value) {
273  18 return anyOf(Arrays.asList(value));
274    }
275   
276    /**
277    * <p>
278    * Creates a matcher that matches any of the given objects by the {@link java.lang.Object#equals(Object)} method.
279    * None of the values must be {@code null}.
280    * </p>
281    * <p>
282    * <b>Important</b>: This method cannot be used interchangably with any of the overloaded versions of {@link ElementMatchers#anyOf(Object...)}
283    * which also apply a type conversion.
284    * </p>
285    *
286    * @param values The input values to be compared against.
287    * @param <T> The type of the matched object.
288    * @return A matcher that checks for the equality with any of the given objects.
289    */
 
290  1586 toggle public static <T> ElementMatcher.Junction<T> anyOf(Iterable<?> values) {
291  1586 ElementMatcher.Junction<T> matcher = none();
292  1586 for (Object value : values) {
293  151 matcher = matcher.or(is(value));
294    }
295  1586 return matcher;
296    }
297   
298    /**
299    * Creates a matcher that matches any of the given types as {@link TypeDescription}s
300    * by the {@link java.lang.Object#equals(Object)} method. None of the values must be {@code null}.
301    *
302    * @param value The input values to be compared against.
303    * @param <T> The type of the matched object.
304    * @return A matcher that checks for the equality with any of the given objects.
305    */
 
306  42 toggle public static <T extends TypeDefinition> ElementMatcher.Junction<T> anyOf(Type... value) {
307  42 return anyOf(new TypeList.Generic.ForLoadedTypes(value));
308    }
309   
310    /**
311    * Creates a matcher that matches any of the given constructors as {@link MethodDescription}s
312    * by the {@link java.lang.Object#equals(Object)} method. None of the values must be {@code null}.
313    *
314    * @param value The input values to be compared against.
315    * @param <T> The type of the matched object.
316    * @return A matcher that checks for the equality with any of the given objects.
317    */
 
318  4 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> anyOf(Constructor<?>... value) {
319  4 return definedMethod(anyOf(new MethodList.ForLoadedType(value, new Method[0])));
320    }
321   
322    /**
323    * Creates a matcher that matches any of the given methods as {@link MethodDescription}s
324    * by the {@link java.lang.Object#equals(Object)} method. None of the values must be {@code null}.
325    *
326    * @param value The input values to be compared against.
327    * @param <T> The type of the matched object.
328    * @return A matcher that checks for the equality with any of the given objects.
329    */
 
330  11 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> anyOf(Method... value) {
331  11 return definedMethod(anyOf(new MethodList.ForLoadedType(new Constructor<?>[0], value)));
332    }
333   
334    /**
335    * Creates a matcher that matches any of the given fields as {@link FieldDescription}s
336    * by the {@link java.lang.Object#equals(Object)} method. None of the values must be {@code null}.
337    *
338    * @param value The input values to be compared against.
339    * @param <T> The type of the matched object.
340    * @return A matcher that checks for the equality with any of the given objects.
341    */
 
342  11 toggle public static <T extends FieldDescription> ElementMatcher.Junction<T> anyOf(Field... value) {
343  11 return definedField(anyOf(new FieldList.ForLoadedFields(value)));
344    }
345   
346    /**
347    * Creates a matcher that matches any of the given annotations as {@link AnnotationDescription}s
348    * by the {@link java.lang.Object#equals(Object)} method. None of the values must be {@code null}.
349    *
350    * @param value The input values to be compared against.
351    * @param <T> The type of the matched object.
352    * @return A matcher that checks for the equality with any of the given objects.
353    */
 
354  24 toggle public static <T extends AnnotationDescription> ElementMatcher.Junction<T> anyOf(Annotation... value) {
355  24 return anyOf(new AnnotationList.ForLoadedAnnotations(value));
356    }
357   
358    /**
359    * Creates a matcher that matches none of the given objects by the {@link java.lang.Object#equals(Object)} method.
360    * None of the values must be {@code null}.
361    *
362    * @param value The input values to be compared against.
363    * @param <T> The type of the matched object.
364    * @return A matcher that checks for the equality with none of the given objects.
365    */
 
366  15 toggle public static <T> ElementMatcher.Junction<T> noneOf(Object... value) {
367  15 return noneOf(Arrays.asList(value));
368    }
369   
370    /**
371    * Creates a matcher that matches none of the given objects by the {@link java.lang.Object#equals(Object)} method.
372    * None of the values must be {@code null}.
373    *
374    * @param values The input values to be compared against.
375    * @param <T> The type of the matched object.
376    * @return A matcher that checks for the equality with none of the given objects.
377    */
 
378  1941 toggle public static <T> ElementMatcher.Junction<T> noneOf(Iterable<?> values) {
379  1941 ElementMatcher.Junction<T> matcher = any();
380  1941 for (Object value : values) {
381  2379 matcher = matcher.and(not(is(value)));
382    }
383  1941 return matcher;
384    }
385   
386    /**
387    * Creates a matcher that matches none of the given types as {@link TypeDescription}s
388    * by the {@link java.lang.Object#equals(Object)} method. None of the values must be {@code null}.
389    *
390    * @param value The input values to be compared against.
391    * @param <T> The type of the matched object.
392    * @return A matcher that checks for the equality with none of the given objects.
393    */
 
394  3 toggle public static <T extends TypeDefinition> ElementMatcher.Junction<T> noneOf(Type... value) {
395  3 return noneOf(new TypeList.Generic.ForLoadedTypes(value));
396    }
397   
398    /**
399    * Creates a matcher that matches none of the given constructors as {@link MethodDescription}s
400    * by the {@link java.lang.Object#equals(Object)} method. None of the values must be {@code null}.
401    *
402    * @param value The input values to be compared against.
403    * @param <T> The type of the matched object.
404    * @return A matcher that checks for the equality with none of the given objects.
405    */
 
406  1 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> noneOf(Constructor<?>... value) {
407  1 return definedMethod(noneOf(new MethodList.ForLoadedType(value, new Method[0])));
408    }
409   
410    /**
411    * Creates a matcher that matches none of the given methods as {@link MethodDescription}s
412    * by the {@link java.lang.Object#equals(Object)} method. None of the values must be {@code null}.
413    *
414    * @param value The input values to be compared against.
415    * @param <T> The type of the matched object.
416    * @return A matcher that checks for the equality with none of the given objects.
417    */
 
418  1 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> noneOf(Method... value) {
419  1 return definedMethod(noneOf(new MethodList.ForLoadedType(new Constructor<?>[0], value)));
420    }
421   
422    /**
423    * Creates a matcher that matches none of the given methods as {@link FieldDescription}s
424    * by the {@link java.lang.Object#equals(Object)} method. None of the values must be {@code null}.
425    *
426    * @param value The input values to be compared against.
427    * @param <T> The type of the matched object.
428    * @return A matcher that checks for the equality with none of the given objects.
429    */
 
430  4 toggle public static <T extends FieldDescription> ElementMatcher.Junction<T> noneOf(Field... value) {
431  4 return definedField(noneOf(new FieldList.ForLoadedFields(value)));
432    }
433   
434    /**
435    * Creates a matcher that matches none of the given annotations as {@link AnnotationDescription}s
436    * by the {@link java.lang.Object#equals(Object)} method. None of the values must be {@code null}.
437    *
438    * @param value The input values to be compared against.
439    * @param <T> The type of the matched object.
440    * @return A matcher that checks for the equality with any of the given objects.
441    */
 
442  3 toggle public static <T extends AnnotationDescription> ElementMatcher.Junction<T> noneOf(Annotation... value) {
443  3 return noneOf(new AnnotationList.ForLoadedAnnotations(value));
444    }
445   
446    /**
447    * Matches an iterable by assuring that at least one element of the iterable collection matches the
448    * provided matcher.
449    *
450    * @param matcher The matcher to apply to each element.
451    * @param <T> The type of the matched object.
452    * @return A matcher that matches an iterable if at least one element matches the provided matcher.
453    */
 
454  1480 toggle public static <T> ElementMatcher.Junction<Iterable<? extends T>> whereAny(ElementMatcher<? super T> matcher) {
455  1480 return new CollectionItemMatcher<T>(matcher);
456    }
457   
458    /**
459    * Matches an iterable by assuring that no element of the iterable collection matches the provided matcher.
460    *
461    * @param matcher The matcher to apply to each element.
462    * @param <T> The type of the matched object.
463    * @return A matcher that matches an iterable if no element matches the provided matcher.
464    */
 
465  1478 toggle public static <T> ElementMatcher.Junction<Iterable<? extends T>> whereNone(ElementMatcher<? super T> matcher) {
466  1478 return not(whereAny(matcher));
467    }
468   
469    /**
470    * Matches a generic type's raw type against the provided raw type.
471    *
472    * @param type The type to match a generic type's erasure against.
473    * @param <T> The type of the matched object.
474    * @return A matcher that matches a generic type's raw type against the provided non-generic type.
475    */
 
476  170 toggle public static <T extends TypeDescription.Generic> ElementMatcher.Junction<T> rawType(Class<?> type) {
477  170 return rawType(is(type));
478    }
479   
480    /**
481    * Matches a generic type's raw type against the provided raw type.
482    *
483    * @param type The type to match a generic type's erasure against.
484    * @param <T> The type of the matched object.
485    * @return A matcher that matches a generic type's raw type against the provided non-generic type.
486    */
 
487  1720 toggle public static <T extends TypeDescription.Generic> ElementMatcher.Junction<T> rawType(TypeDescription type) {
488  1720 return rawType(is(type));
489    }
490   
491    /**
492    * Converts a matcher for a type description into a matcher for a raw type of the matched generic type against the given matcher. A wildcard
493    * type which does not define a raw type results in a negative match.
494    *
495    * @param matcher The matcher to match the matched object's raw type against.
496    * @param <T> The type of the matched object.
497    * @return A type matcher for a generic type that matches the matched type's raw type against the given type description matcher.
498    */
 
499  12818 toggle public static <T extends TypeDescription.Generic> ElementMatcher.Junction<T> rawType(ElementMatcher<? super TypeDescription> matcher) {
500  12818 return new RawTypeMatcher<T>(matcher);
501    }
502   
503    /**
504    * Matches an iteration of generic types' erasures against the provided raw types.
505    *
506    * @param type The types to match.
507    * @param <T> The type of the matched object.
508    * @return A matcher that matches an iteration of generic types' raw types against the provided non-generic types.
509    */
 
510  61 toggle public static <T extends Iterable<? extends TypeDescription.Generic>> ElementMatcher.Junction<T> rawTypes(Class<?>... type) {
511  61 return rawTypes(new TypeList.ForLoadedTypes(type));
512    }
513   
514    /**
515    * Matches an iteration of generic types' erasures against the provided raw types.
516    *
517    * @param type The types to match.
518    * @param <T> The type of the matched object.
519    * @return A matcher that matches an iteration of generic types' raw types against the provided non-generic types.
520    */
 
521  3 toggle public static <T extends Iterable<? extends TypeDescription.Generic>> ElementMatcher.Junction<T> rawTypes(TypeDescription... type) {
522  3 return rawTypes(Arrays.asList(type));
523    }
524   
525    /**
526    * Matches an iteration of generic types' erasures against the provided raw types.
527    *
528    * @param types The types to match.
529    * @param <T> The type of the matched object.
530    * @return A matcher that matches an iteration of generic types' raw types against the provided non-generic types.
531    */
 
532  64 toggle public static <T extends Iterable<? extends TypeDescription.Generic>> ElementMatcher.Junction<T> rawTypes(
533    Iterable<? extends TypeDescription> types) {
534  64 List<ElementMatcher<? super TypeDescription>> typeMatchers = new ArrayList<ElementMatcher<? super TypeDescription>>();
535  64 for (TypeDescription type : types) {
536  76 typeMatchers.add(is(type));
537    }
538  64 return rawTypes(new CollectionOneToOneMatcher<TypeDescription>(typeMatchers));
539    }
540   
541    /**
542    * Applies the provided matcher to an iteration og generic types' generic types.
543    *
544    * @param matcher The matcher to apply at the erased types.
545    * @param <T> The type of the matched object.
546    * @return A matcher that matches an iteration of generic types' raw types against the provided matcher.
547    */
 
548  64 toggle public static <T extends Iterable<? extends TypeDescription.Generic>> ElementMatcher.Junction<T> rawTypes(
549    ElementMatcher<? super Iterable<? extends TypeDescription>> matcher) {
550  64 return new CollectionRawTypeMatcher<T>(matcher);
551    }
552   
553    /**
554    * Matches a type variable with the given name.
555    *
556    * @param symbol The name of the type variable to be match.
557    * @param <T> The type of the matched object.
558    * @return A matcher that matches type variables with the given name.
559    */
 
560  3 toggle public static <T extends TypeDefinition> ElementMatcher.Junction<T> isVariable(String symbol) {
561  3 return isVariable(named(symbol));
562    }
563   
564    /**
565    * Matches a type variable with the given name.
566    *
567    * @param matcher A matcher for the type variable's name.
568    * @param <T> The type of the matched object.
569    * @return A matcher that matches type variables with the given name.
570    */
 
571  3 toggle public static <T extends TypeDefinition> ElementMatcher.Junction<T> isVariable(ElementMatcher<? super NamedElement> matcher) {
572  3 return new TypeSortMatcher<T>(anyOf(TypeDefinition.Sort.VARIABLE, TypeDefinition.Sort.VARIABLE_SYMBOLIC)).and(matcher);
573    }
574   
575    /**
576    * Matches a {@link NamedElement} for its exact name.
577    *
578    * @param name The expected name.
579    * @param <T> The type of the matched object.
580    * @return An element matcher for a named element's exact name.
581    */
 
582  17860 toggle public static <T extends NamedElement> ElementMatcher.Junction<T> named(String name) {
583  17860 return new NameMatcher<T>(new StringMatcher(name, StringMatcher.Mode.EQUALS_FULLY));
584    }
585   
586    /**
587    * Matches a {@link NamedElement} for its name. The name's
588    * capitalization is ignored.
589    *
590    * @param name The expected name.
591    * @param <T> The type of the matched object.
592    * @return An element matcher for a named element's name.
593    */
 
594  3 toggle public static <T extends NamedElement> ElementMatcher.Junction<T> namedIgnoreCase(String name) {
595  3 return new NameMatcher<T>(new StringMatcher(name, StringMatcher.Mode.EQUALS_FULLY_IGNORE_CASE));
596    }
597   
598    /**
599    * Matches a {@link NamedElement} for its name's prefix.
600    *
601    * @param prefix The expected name's prefix.
602    * @param <T> The type of the matched object.
603    * @return An element matcher for a named element's name's prefix.
604    */
 
605  214 toggle public static <T extends NamedElement> ElementMatcher.Junction<T> nameStartsWith(String prefix) {
606  214 return new NameMatcher<T>(new StringMatcher(prefix, StringMatcher.Mode.STARTS_WITH));
607    }
608   
609    /**
610    * Matches a {@link NamedElement} for its name's prefix. The name's
611    * capitalization is ignored.
612    *
613    * @param prefix The expected name's prefix.
614    * @param <T> The type of the matched object.
615    * @return An element matcher for a named element's name's prefix.
616    */
 
617  3 toggle public static <T extends NamedElement> ElementMatcher.Junction<T> nameStartsWithIgnoreCase(String prefix) {
618  3 return new NameMatcher<T>(new StringMatcher(prefix, StringMatcher.Mode.STARTS_WITH_IGNORE_CASE));
619    }
620   
621    /**
622    * Matches a {@link NamedElement} for its name's suffix.
623    *
624    * @param suffix The expected name's suffix.
625    * @param <T> The type of the matched object.
626    * @return An element matcher for a named element's name's suffix.
627    */
 
628  3 toggle public static <T extends NamedElement> ElementMatcher.Junction<T> nameEndsWith(String suffix) {
629  3 return new NameMatcher<T>(new StringMatcher(suffix, StringMatcher.Mode.ENDS_WITH));
630    }
631   
632    /**
633    * Matches a {@link NamedElement} for its name's suffix. The name's
634    * capitalization is ignored.
635    *
636    * @param suffix The expected name's suffix.
637    * @param <T> The type of the matched object.
638    * @return An element matcher for a named element's name's suffix.
639    */
 
640  3 toggle public static <T extends NamedElement> ElementMatcher.Junction<T> nameEndsWithIgnoreCase(String suffix) {
641  3 return new NameMatcher<T>(new StringMatcher(suffix, StringMatcher.Mode.ENDS_WITH_IGNORE_CASE));
642    }
643   
644    /**
645    * Matches a {@link NamedElement} for an infix of its name.
646    *
647    * @param infix The expected infix of the name.
648    * @param <T> The type of the matched object.
649    * @return An element matcher for a named element's name's infix.
650    */
 
651  3 toggle public static <T extends NamedElement> ElementMatcher.Junction<T> nameContains(String infix) {
652  3 return new NameMatcher<T>(new StringMatcher(infix, StringMatcher.Mode.CONTAINS));
653    }
654   
655    /**
656    * Matches a {@link NamedElement} for an infix of its name. The name's
657    * capitalization is ignored.
658    *
659    * @param infix The expected infix of the name.
660    * @param <T> The type of the matched object.
661    * @return An element matcher for a named element's name's infix.
662    */
 
663  3 toggle public static <T extends NamedElement> ElementMatcher.Junction<T> nameContainsIgnoreCase(String infix) {
664  3 return new NameMatcher<T>(new StringMatcher(infix, StringMatcher.Mode.CONTAINS_IGNORE_CASE));
665    }
666   
667    /**
668    * Matches a {@link NamedElement} name against a regular expression.
669    *
670    * @param regex The regular expression to match the name against.
671    * @param <T> The type of the matched object.
672    * @return An element matcher for a named element's name's against the given regular expression.
673    */
 
674  3 toggle public static <T extends NamedElement> ElementMatcher.Junction<T> nameMatches(String regex) {
675  3 return new NameMatcher<T>(new StringMatcher(regex, StringMatcher.Mode.MATCHES));
676    }
677   
678    /**
679    * Matches a {@link NamedElement.WithOptionalName} for having an explicit name.
680    *
681    * @param <T> The type of the matched object.
682    * @return An element matcher that checks if the matched optionally named element has an explicit name.
683    */
 
684  2 toggle public static <T extends NamedElement.WithOptionalName> ElementMatcher.Junction<T> isNamed() {
685  2 return new IsNamedMatcher<T>();
686    }
687   
688    /**
689    * Matches a {@link ByteCodeElement}'s descriptor against a given value.
690    *
691    * @param descriptor The expected descriptor.
692    * @param <T> The type of the matched object.
693    * @return A matcher for the given {@code descriptor}.
694    */
 
695  44 toggle public static <T extends ByteCodeElement> ElementMatcher.Junction<T> hasDescriptor(String descriptor) {
696  44 return new DescriptorMatcher<T>(new StringMatcher(descriptor, StringMatcher.Mode.EQUALS_FULLY));
697    }
698   
699    /**
700    * Matches a {@link ByteCodeElement} for being declared by a given {@link java.lang.Class}. This matcher matches
701    * a declared element's raw declaring type.
702    *
703    * @param type The type that is expected to declare the matched byte code element.
704    * @param <T> The type of the matched object.
705    * @return A matcher for byte code elements being declared by the given {@code type}.
706    */
 
707  459 toggle public static <T extends ByteCodeElement> ElementMatcher.Junction<T> isDeclaredBy(Class<?> type) {
708  459 return isDeclaredBy(new TypeDescription.ForLoadedType(type));
709    }
710   
711    /**
712    * Matches a {@link ByteCodeElement} for being declared by a given {@link TypeDescription}. This matcher matches
713    * a declared element's raw declaring type.
714    *
715    * @param type The type that is expected to declare the matched byte code element.
716    * @param <T> The type of the matched object.
717    * @return A matcher for byte code elements being declared by the given {@code type}.
718    */
 
719  3984 toggle public static <T extends ByteCodeElement> ElementMatcher.Junction<T> isDeclaredBy(TypeDescription type) {
720  3984 return isDeclaredBy(is(type));
721    }
722   
723    /**
724    * Matches a {@link ByteCodeElement} for being declared by a {@link TypeDescription} that is matched by the given matcher. This matcher matches
725    * a declared element's raw declaring type.
726    *
727    * @param matcher A matcher for the declaring type of the matched byte code element as long as it
728    * is not {@code null}.
729    * @param <T> The type of the matched object.
730    * @return A matcher for byte code elements being declared by a type matched by the given {@code matcher}.
731    */
 
732  4517 toggle public static <T extends ByteCodeElement> ElementMatcher.Junction<T> isDeclaredBy(ElementMatcher<? super TypeDescription> matcher) {
733  4517 return isDeclaredByGeneric(rawType(matcher));
734    }
735   
736    /**
737    * Matches a {@link ByteCodeElement} for being declared by a given generic {@link Type}.
738    *
739    * @param type The type that is expected to declare the matched byte code element.
740    * @param <T> The type of the matched object.
741    * @return A matcher for byte code elements being declared by the given {@code type}.
742    */
 
743  3 toggle public static <T extends ByteCodeElement> ElementMatcher.Junction<T> isDeclaredByGeneric(Type type) {
744  3 return isDeclaredByGeneric(TypeDefinition.Sort.describe(type));
745    }
746   
747    /**
748    * Matches a {@link ByteCodeElement} for being declared by a given {@link TypeDescription.Generic}.
749    *
750    * @param type The type that is expected to declare the matched byte code element.
751    * @param <T> The type of the matched object.
752    * @return A matcher for byte code elements being declared by the given {@code type}.
753    */
 
754  3 toggle public static <T extends ByteCodeElement> ElementMatcher.Junction<T> isDeclaredByGeneric(TypeDescription.Generic type) {
755  3 return isDeclaredByGeneric(is(type));
756    }
757   
758    /**
759    * Matches a {@link ByteCodeElement} for being declared by a {@link TypeDescription.Generic} that is matched by the given matcher.
760    *
761    * @param matcher A matcher for the declaring type of the matched byte code element as long as it is not {@code null}.
762    * @param <T> The type of the matched object.
763    * @return A matcher for byte code elements being declared by a type matched by the given {@code matcher}.
764    */
 
765  4520 toggle public static <T extends ByteCodeElement> ElementMatcher.Junction<T> isDeclaredByGeneric(ElementMatcher<? super TypeDescription.Generic> matcher) {
766  4520 return new DeclaringTypeMatcher<T>(matcher);
767    }
768   
769    /**
770    * Matches a {@link ByteCodeElement} that is visible to a given {@link java.lang.Class}.
771    *
772    * @param type The type that a matched byte code element is expected to be visible to.
773    * @param <T> The type of the matched object.
774    * @return A matcher for a byte code element to be visible to a given {@code type}.
775    */
 
776  2 toggle public static <T extends ByteCodeElement> ElementMatcher.Junction<T> isVisibleTo(Class<?> type) {
777  2 return isVisibleTo(new TypeDescription.ForLoadedType(type));
778    }
779   
780    /**
781    * Matches a {@link ByteCodeElement} that is visible to a given
782    * {@link TypeDescription}.
783    *
784    * @param type The type that a matched byte code element is expected to be visible to.
785    * @param <T> The type of the matched object.
786    * @return A matcher for a byte code element to be visible to a given {@code type}.
787    */
 
788  8088 toggle public static <T extends ByteCodeElement> ElementMatcher.Junction<T> isVisibleTo(TypeDescription type) {
789  8088 return new VisibilityMatcher<T>(type);
790    }
791   
792    /**
793    * Matches a {@link ModifierReviewable} that is {@code abstract}.
794    *
795    * @param <T> The type of the matched object.
796    * @return A matcher for a {@code abstract} modifier reviewable.
797    */
 
798  48 toggle public static <T extends ModifierReviewable> ElementMatcher.Junction<T> isAbstract() {
799  48 return new ModifierMatcher<T>(ModifierMatcher.Mode.ABSTRACT);
800    }
801   
802    /**
803    * Matches an {@link net.bytebuddy.description.annotation.AnnotatedCodeElement} for declared annotations.
804    * This matcher does not match inherited annotations which only exist for classes. Use
805    * {@link net.bytebuddy.matcher.ElementMatchers#inheritsAnnotation(Class)} for matching inherited annotations.
806    *
807    * @param type The annotation type to match against.
808    * @param <T> The type of the matched object.
809    * @return A matcher that validates that an annotated element is annotated with an annotation of {@code type}.
810    */
 
811  60 toggle public static <T extends AnnotatedCodeElement> ElementMatcher.Junction<T> isAnnotatedWith(Class<? extends Annotation> type) {
812  60 return isAnnotatedWith(new TypeDescription.ForLoadedType(type));
813    }
814   
815    /**
816    * Matches an {@link net.bytebuddy.description.annotation.AnnotatedCodeElement} for declared annotations.
817    * This matcher does not match inherited annotations which only exist for classes. Use
818    * {@link net.bytebuddy.matcher.ElementMatchers#inheritsAnnotation(TypeDescription)}
819    * for matching inherited annotations.
820    *
821    * @param type The annotation type to match against.
822    * @param <T> The type of the matched object.
823    * @return A matcher that validates that an annotated element is annotated with an annotation of {@code type}.
824    */
 
825  60 toggle public static <T extends AnnotatedCodeElement> ElementMatcher.Junction<T> isAnnotatedWith(TypeDescription type) {
826  60 return isAnnotatedWith(is(type));
827    }
828   
829    /**
830    * Matches an {@link net.bytebuddy.description.annotation.AnnotatedCodeElement} for declared annotations.
831    * This matcher does not match inherited annotations which only exist for classes. Use
832    * {@link net.bytebuddy.matcher.ElementMatchers#inheritsAnnotation(net.bytebuddy.matcher.ElementMatcher)}
833    * for matching inherited annotations.
834    *
835    * @param matcher The matcher to apply to any annotation's type found on the matched annotated element.
836    * @param <T> The type of the matched object.
837    * @return A matcher that validates that an annotated element is annotated with an annotation of a type
838    * that matches the given {@code matcher}.
839    */
 
840  60 toggle public static <T extends AnnotatedCodeElement> ElementMatcher.Junction<T> isAnnotatedWith(ElementMatcher<? super TypeDescription> matcher) {
841  60 return declaresAnnotation(annotationType(matcher));
842    }
843   
844    /**
845    * Matches an {@link net.bytebuddy.description.annotation.AnnotatedCodeElement} to declare any annotation
846    * that matches the given matcher. Note that this matcher does not match inherited annotations that only exist
847    * for types. Use {@link net.bytebuddy.matcher.ElementMatchers#inheritsAnnotation(net.bytebuddy.matcher.ElementMatcher)}
848    * for matching inherited annotations.
849    *
850    * @param matcher A matcher to apply on any declared annotation of the matched annotated element.
851    * @param <T> The type of the matched object.
852    * @return A matcher that validates that an annotated element is annotated with an annotation that matches
853    * the given {@code matcher}.
854    */
 
855  60 toggle public static <T extends AnnotatedCodeElement> ElementMatcher.Junction<T> declaresAnnotation(ElementMatcher<? super AnnotationDescription> matcher) {
856  60 return new DeclaringAnnotationMatcher<T>(new CollectionItemMatcher<AnnotationDescription>(matcher));
857    }
858   
859    /**
860    * Matches a {@link ModifierReviewable} that is {@code public}.
861    *
862    * @param <T> The type of the matched object.
863    * @return A matcher for a {@code public} modifier reviewable.
864    */
 
865  6 toggle public static <T extends ModifierReviewable> ElementMatcher.Junction<T> isPublic() {
866  6 return new ModifierMatcher<T>(ModifierMatcher.Mode.PUBLIC);
867    }
868   
869    /**
870    * Matches a {@link ModifierReviewable} that is {@code protected}.
871    *
872    * @param <T> The type of the matched object.
873    * @return A matcher for a {@code protected} modifier reviewable.
874    */
 
875  4 toggle public static <T extends ModifierReviewable> ElementMatcher.Junction<T> isProtected() {
876  4 return new ModifierMatcher<T>(ModifierMatcher.Mode.PROTECTED);
877    }
878   
879    /**
880    * Matches a {@link ModifierReviewable} that is package-private.
881    *
882    * @param <T> The type of the matched object.
883    * @return A matcher for a package-private modifier reviewable.
884    */
 
885  2 toggle public static <T extends ModifierReviewable> ElementMatcher.Junction<T> isPackagePrivate() {
886  2 return not(isPublic().or(isProtected()).or(isPrivate()));
887    }
888   
889    /**
890    * Matches a {@link ModifierReviewable} that is {@code private}.
891    *
892    * @param <T> The type of the matched object.
893    * @return A matcher for a {@code private} modifier reviewable.
894    */
 
895  4 toggle public static <T extends ModifierReviewable> ElementMatcher.Junction<T> isPrivate() {
896  4 return new ModifierMatcher<T>(ModifierMatcher.Mode.PRIVATE);
897    }
898   
899    /**
900    * Matches a {@link ModifierReviewable} that is {@code final}.
901    *
902    * @param <T> The type of the matched object.
903    * @return A matcher for a {@code final} modifier reviewable.
904    */
 
905  1492 toggle public static <T extends ModifierReviewable> ElementMatcher.Junction<T> isFinal() {
906  1492 return new ModifierMatcher<T>(ModifierMatcher.Mode.FINAL);
907    }
908   
909    /**
910    * Matches a {@link ModifierReviewable} that is {@code static}.
911    *
912    * @param <T> The type of the matched object.
913    * @return A matcher for a {@code static} modifier reviewable.
914    */
 
915  134 toggle public static <T extends ModifierReviewable> ElementMatcher.Junction<T> isStatic() {
916  134 return new ModifierMatcher<T>(ModifierMatcher.Mode.STATIC);
917    }
918   
919    /**
920    * Matches a {@link ModifierReviewable} that is synthetic.
921    *
922    * @param <T> The type of the matched object.
923    * @return A matcher for a synthetic modifier reviewable.
924    */
 
925  1585 toggle public static <T extends ModifierReviewable> ElementMatcher.Junction<T> isSynthetic() {
926  1585 return new ModifierMatcher<T>(ModifierMatcher.Mode.SYNTHETIC);
927    }
928   
929    /**
930    * Matches a {@link MethodDescription} that is {@code synchronized}.
931    *
932    * @param <T> The type of the matched object.
933    * @return A matcher for a {@code synchronized} method description.
934    */
 
935  2 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isSynchronized() {
936  2 return new ModifierMatcher<T>(ModifierMatcher.Mode.SYNCHRONIZED);
937    }
938   
939    /**
940    * Matches a {@link MethodDescription} that is {@code native}.
941    *
942    * @param <T> The type of the matched object.
943    * @return A matcher for a {@code native} method description.
944    */
 
945  2 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isNative() {
946  2 return new ModifierMatcher<T>(ModifierMatcher.Mode.NATIVE);
947    }
948   
949    /**
950    * Matches a {@link MethodDescription} that is {@code strictfp}.
951    *
952    * @param <T> The type of the matched object.
953    * @return A matcher for a {@code strictfp} method description.
954    */
 
955  2 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isStrict() {
956  2 return new ModifierMatcher<T>(ModifierMatcher.Mode.STRICT);
957    }
958   
959    /**
960    * Matches a {@link MethodDescription} that is a var-args.
961    *
962    * @param <T> The type of the matched object.
963    * @return A matcher for a var-args method description.
964    */
 
965  2 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isVarArgs() {
966  2 return new ModifierMatcher<T>(ModifierMatcher.Mode.VAR_ARGS);
967    }
968   
969    /**
970    * Matches a {@link MethodDescription} that is a bridge.
971    *
972    * @param <T> The type of the matched object.
973    * @return A matcher for a bridge method.
974    */
 
975  26 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isBridge() {
976  26 return new ModifierMatcher<T>(ModifierMatcher.Mode.BRIDGE);
977    }
978   
979    /**
980    * Matches {@link MethodDescription}s that return a given generic type.
981    *
982    * @param type The generic type the matched method is expected to return.
983    * @param <T> The type of the matched object.
984    * @return An element matcher that matches a given generic return type for a method description.
985    */
 
986  2 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> returnsGeneric(Type type) {
987  2 return returnsGeneric(TypeDefinition.Sort.describe(type));
988    }
989   
990    /**
991    * Matches {@link MethodDescription}s that returns a given
992    * {@link TypeDescription}.
993    *
994    * @param type The type the matched method is expected to return.
995    * @param <T> The type of the matched object.
996    * @return An element matcher that matches a given return type for a method description.
997    */
 
998  2 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> returnsGeneric(TypeDescription.Generic type) {
999  2 return returnsGeneric(is(type));
1000    }
1001   
1002    /**
1003    * Matches {@link MethodDescription}s that return a given erasure type.
1004    *
1005    * @param type The raw type the matched method is expected to return.
1006    * @param <T> The type of the matched object.
1007    * @return An element matcher that matches a given return type for a method description.
1008    */
 
1009  157 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> returns(Class<?> type) {
1010  157 return returnsGeneric(rawType(type));
1011    }
1012   
1013    /**
1014    * Matches {@link MethodDescription}s that return a given erasure type.
1015    *
1016    * @param type The raw type the matched method is expected to return.
1017    * @param <T> The type of the matched object.
1018    * @return An element matcher that matches a given return type for a method description.
1019    */
 
1020  3444 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> returns(TypeDescription type) {
1021  3444 return returns(is(type));
1022    }
1023   
1024    /**
1025    * Matches a method's return type's erasure by the given matcher.
1026    *
1027    * @param matcher The matcher to apply to a method's return type's erasure.
1028    * @param <T> The type of the matched object.
1029    * @return A matcher that matches the matched method's return type's erasure.
1030    */
 
1031  4920 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> returns(ElementMatcher<? super TypeDescription> matcher) {
1032  4920 return returnsGeneric(rawType(matcher));
1033    }
1034   
1035    /**
1036    * Matches {@link MethodDescription}s that match a matched method's return type.
1037    *
1038    * @param matcher A matcher to apply onto a matched method's return type.
1039    * @param <T> The type of the matched object.
1040    * @return An element matcher that matches a given return type against another {@code matcher}.
1041    */
 
1042  5098 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> returnsGeneric(ElementMatcher<? super TypeDescription.Generic> matcher) {
1043  5098 return new MethodReturnTypeMatcher<T>(matcher);
1044    }
1045   
1046    /**
1047    * Matches {@link MethodDescription}s that define a given generic type as a parameter at the given index.
1048    *
1049    * @param index The index of the parameter.
1050    * @param type The generic type the matched method is expected to define as a parameter type.
1051    * @param <T> The type of the matched object.
1052    * @return An element matcher that matches a given generic return type for a method description.
1053    */
 
1054  3 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> takesGenericArgument(int index, Type type) {
1055  3 return takesGenericArgument(index, TypeDefinition.Sort.describe(type));
1056    }
1057   
1058    /**
1059    * Matches {@link MethodDescription}s that define a given generic type as a parameter at the given index.
1060    *
1061    * @param index The index of the parameter.
1062    * @param type The generic type the matched method is expected to define as a parameter type.
1063    * @param <T> The type of the matched object.
1064    * @return An element matcher that matches a given generic return type for a method description.
1065    */
 
1066  3 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> takesGenericArgument(int index, TypeDescription.Generic type) {
1067  3 return takesGenericArgument(index, is(type));
1068    }
1069   
1070    /**
1071    * Matches {@link MethodDescription}s that define a given generic type as a parameter at the given index.
1072    *
1073    * @param index The index of the parameter.
1074    * @param matcher A matcher for the generic type the matched method is expected to define as a parameter type.
1075    * @param <T> The type of the matched object.
1076    * @return An element matcher that matches a given generic return type for a method description.
1077    */
 
1078  9 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> takesGenericArgument(int index, ElementMatcher<? super TypeDescription.Generic> matcher) {
1079  9 return takesGenericArguments(new CollectionElementMatcher<TypeDescription.Generic>(index, matcher));
1080    }
1081   
1082    /**
1083    * Matches a method description that takes the provided generic arguments.
1084    *
1085    * @param type The arguments to match against the matched method.
1086    * @param <T> The type of the matched object.
1087    * @return A method matcher that matches a method's generic parameter types against the supplied arguments.
1088    */
 
1089  2 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> takesGenericArguments(Type... type) {
1090  2 return takesGenericArguments(new TypeList.Generic.ForLoadedTypes(type));
1091    }
1092   
1093    /**
1094    * Matches a method description that takes the provided generic arguments.
1095    *
1096    * @param type The arguments to match against the matched method.
1097    * @param <T> The type of the matched object.
1098    * @return A method matcher that matches a method's generic parameter types against the supplied arguments.
1099    */
 
1100  1 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> takesGenericArguments(TypeDefinition... type) {
1101  1 return takesGenericArguments((Arrays.asList(type)));
1102    }
1103   
1104    /**
1105    * Matches a method description that takes the provided generic arguments.
1106    *
1107    * @param types The arguments to match against the matched method.
1108    * @param <T> The type of the matched object.
1109    * @return A method matcher that matches a method's generic parameter types against the supplied arguments.
1110    */
 
1111  4 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> takesGenericArguments(List<? extends TypeDefinition> types) {
1112  4 List<ElementMatcher<? super TypeDescription.Generic>> typeMatchers = new ArrayList<ElementMatcher<? super TypeDescription.Generic>>();
1113  4 for (TypeDefinition type : types) {
1114  4 typeMatchers.add(is(type));
1115    }
1116  4 return takesGenericArguments(new CollectionOneToOneMatcher<TypeDescription.Generic>(typeMatchers));
1117    }
1118   
1119    /**
1120    * Matches a {@link MethodDescription} by applying an iterable collection of element matcher on any parameter's {@link TypeDescription}.
1121    *
1122    * @param matchers The matcher that are applied onto the parameter types of the matched method description.
1123    * @param <T> The type of the matched object.
1124    * @return A matcher that matches a method description by applying another element matcher onto each
1125    * parameter's type.
1126    */
 
1127  2030 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> takesGenericArguments(ElementMatcher<? super Iterable<? extends TypeDescription.Generic>> matchers) {
1128  2030 return new MethodParametersMatcher<T>(new MethodParameterTypesMatcher<ParameterList<?>>(matchers));
1129    }
1130   
1131    /**
1132    * Matches {@link MethodDescription}s that define a given generic type as a parameter at the given index.
1133    *
1134    * @param index The index of the parameter.
1135    * @param type The erasure of the type the matched method is expected to define as a parameter type.
1136    * @param <T> The type of the matched object.
1137    * @return An element matcher that matches a given generic return type for a method description.
1138    */
 
1139  5 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> takesArgument(int index, Class<?> type) {
1140  5 return takesGenericArgument(index, rawType(type));
1141    }
1142   
1143    /**
1144    * Matches {@link MethodDescription}s that define a given generic type as a parameter at the given index.
1145    *
1146    * @param index The index of the parameter.
1147    * @param type The erasure of the type the matched method is expected to define as a parameter type.
1148    * @param <T> The type of the matched object.
1149    * @return An element matcher that matches a given generic return type for a method description.
1150    */
 
1151  1 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> takesArgument(int index, TypeDescription type) {
1152  1 return takesGenericArgument(index, rawType(type));
1153    }
1154   
1155    /**
1156    * Matches a method description that takes the provided raw arguments.
1157    *
1158    * @param type The arguments to match against the matched method.
1159    * @param <T> The type of the matched object.
1160    * @return A method matcher that matches a method's raw parameter types against the supplied arguments.
1161    */
 
1162  59 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> takesArguments(Class<?>... type) {
1163  59 return takesGenericArguments(rawTypes(type));
1164    }
1165   
1166    /**
1167    * Matches a method description that takes the provided raw arguments.
1168    *
1169    * @param type The arguments to match against the matched method.
1170    * @param <T> The type of the matched object.
1171    * @return A method matcher that matches a method's raw parameter types against the supplied arguments.
1172    */
 
1173  3 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> takesArguments(TypeDescription... type) {
1174  3 return takesGenericArguments(rawTypes(type));
1175    }
1176   
1177    /**
1178    * Matches a method description that takes the provided raw arguments.
1179    *
1180    * @param types The arguments to match against the matched method.
1181    * @param <T> The type of the matched object.
1182    * @return A method matcher that matches a method's raw parameter types against the supplied arguments.
1183    */
 
1184  1953 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> takesArguments(Iterable<? extends TypeDescription> types) {
1185  1953 List<ElementMatcher<? super TypeDescription.Generic>> typeMatchers = new ArrayList<ElementMatcher<? super TypeDescription.Generic>>();
1186  1953 for (TypeDescription type : types) {
1187  1710 typeMatchers.add(rawType(type));
1188    }
1189  1953 return takesGenericArguments(new CollectionOneToOneMatcher<TypeDescription.Generic>(typeMatchers));
1190    }
1191   
1192    /**
1193    * Matches a {@link MethodDescription} by the number of its parameters.
1194    *
1195    * @param length The expected length.
1196    * @param <T> The type of the matched object.
1197    * @return A matcher that matches a method description by the number of its parameters.
1198    */
 
1199  1678 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> takesArguments(int length) {
1200  1678 return new MethodParametersMatcher<T>(new CollectionSizeMatcher<ParameterList<?>>(length));
1201    }
1202   
1203    /**
1204    * Matches a {@link MethodDescription} by validating that its parameters
1205    * fulfill a given constraint.
1206    *
1207    * @param matcher The matcher to apply for validating the parameters.
1208    * @param <T> The type of the matched object.
1209    * @return A matcher that matches a method description's parameters against the given constraint.
1210    */
 
1211  1476 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> hasParameters(
1212    ElementMatcher<? super Iterable<? extends ParameterDescription>> matcher) {
1213  1476 return new MethodParametersMatcher<T>(matcher);
1214    }
1215   
1216    /**
1217    * Matches a {@link MethodDescription} by its capability to throw a given
1218    * checked exception. For specifying a non-checked exception, any method is matched.
1219    *
1220    * @param exceptionType The type of the exception that should be declared by the method to be matched.
1221    * @param <T> The type of the matched object.
1222    * @return A matcher that matches a method description by its declaration of throwing a checked exception.
1223    */
 
1224  8 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> canThrow(Class<? extends Throwable> exceptionType) {
1225  8 return canThrow(new TypeDescription.ForLoadedType(exceptionType));
1226    }
1227   
1228    /**
1229    * Matches a {@link MethodDescription} by its capability to throw a given
1230    * checked exception. For specifying a non-checked exception, any method is matched.
1231    *
1232    * @param exceptionType The type of the exception that should be declared by the method to be matched.
1233    * @param <T> The type of the matched object.
1234    * @return A matcher that matches a method description by its declaration of throwing a checked exception.
1235    */
 
1236  8 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> canThrow(TypeDescription exceptionType) {
1237  8 return exceptionType.isAssignableTo(RuntimeException.class) || exceptionType.isAssignableTo(Error.class)
1238    ? new BooleanMatcher<T>(true)
1239    : ElementMatchers.<T>declaresGenericException(new CollectionItemMatcher<TypeDescription.Generic>(rawType(isSuperTypeOf(exceptionType))));
1240    }
1241   
1242    /**
1243    * Matches a method that declares the given generic exception type. For non-generic type, this matcher behaves identically to
1244    * {@link ElementMatchers#declaresException(Class)}. For exceptions that are expressed as type variables, only exceptions
1245    * that are represented as this type variable are matched.
1246    *
1247    * @param exceptionType The generic exception type that is matched exactly.
1248    * @param <T> The type of the matched object.
1249    * @return A matcher that matches any method that exactly matches the provided generic exception.
1250    */
 
1251  2 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> declaresGenericException(Type exceptionType) {
1252  2 return declaresGenericException(TypeDefinition.Sort.describe(exceptionType));
1253    }
1254   
1255    /**
1256    * Matches a method that declares the given generic exception type. For non-generic type, this matcher behaves identically to
1257    * {@link ElementMatchers#declaresException(TypeDescription)}. For exceptions that are expressed as type variables, only exceptions
1258    * that are represented as this type variable are matched.
1259    *
1260    * @param exceptionType The generic exception type that is matched exactly.
1261    * @param <T> The type of the matched object.
1262    * @return A matcher that matches any method that exactly matches the provided generic exception.
1263    */
 
1264  2 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> declaresGenericException(TypeDescription.Generic exceptionType) {
1265  2 return !exceptionType.getSort().isWildcard() && exceptionType.asErasure().isAssignableTo(Throwable.class)
1266    ? ElementMatchers.<T>declaresGenericException(new CollectionItemMatcher<TypeDescription.Generic>(is(exceptionType)))
1267    : new BooleanMatcher<T>(false);
1268    }
1269   
1270    /**
1271    * Matches a method that declares the given generic exception type as a (erased) exception type.
1272    *
1273    * @param exceptionType The exception type that is matched.
1274    * @param <T> The type of the matched object.
1275    * @return A matcher that matches any method that exactly matches the provided exception.
1276    */
 
1277  10 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> declaresException(Class<? extends Throwable> exceptionType) {
1278  10 return declaresException(new TypeDescription.ForLoadedType(exceptionType));
1279    }
1280   
1281    /**
1282    * Matches a method that declares the given generic exception type as a (erased) exception type.
1283    *
1284    * @param exceptionType The exception type that is matched.
1285    * @param <T> The type of the matched object.
1286    * @return A matcher that matches any method that exactly matches the provided exception.
1287    */
 
1288  10 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> declaresException(TypeDescription exceptionType) {
1289  10 return exceptionType.isAssignableTo(Throwable.class)
1290    ? ElementMatchers.<T>declaresGenericException(new CollectionItemMatcher<TypeDescription.Generic>(rawType(exceptionType)))
1291    : new BooleanMatcher<T>(false);
1292    }
1293   
1294    /**
1295    * Matches a method's generic exception types against the provided matcher.
1296    *
1297    * @param matcher The exception matcher to apply onto the matched method's generic exceptions.
1298    * @param <T> The type of the matched object.
1299    * @return A matcher that applies the provided matcher to a method's generic exception types.
1300    */
 
1301  15 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> declaresGenericException(
1302    ElementMatcher<? super Iterable<? extends TypeDescription.Generic>> matcher) {
1303  15 return new MethodExceptionTypeMatcher<T>(matcher);
1304    }
1305   
1306    /**
1307    * Matches a {@link TypeDescription} that is an interface.
1308    *
1309    * @param <T> The type of the matched object.
1310    * @return A matcher for an interface.
1311    */
 
1312  180 toggle public static <T extends TypeDescription> ElementMatcher.Junction<T> isInterface() {
1313  180 return new ModifierMatcher<T>(ModifierMatcher.Mode.INTERFACE);
1314    }
1315   
1316    /**
1317    * Only matches method descriptions that represent a {@link java.lang.reflect.Method}.
1318    *
1319    * @param <T> The type of the matched object.
1320    * @return A matcher that only matches method descriptions that represent a Java method.
1321    */
 
1322  465 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isMethod() {
1323  465 return new MethodSortMatcher<T>(MethodSortMatcher.Sort.METHOD);
1324    }
1325   
1326    /**
1327    * Only matches method descriptions that represent a {@link java.lang.reflect.Constructor}.
1328    *
1329    * @param <T> The type of the matched object.
1330    * @return A matcher that only matches method descriptions that represent a Java constructor.
1331    */
 
1332  3649 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isConstructor() {
1333  3649 return new MethodSortMatcher<T>(MethodSortMatcher.Sort.CONSTRUCTOR);
1334    }
1335   
1336    /**
1337    * Only matches method descriptions that represent a {@link java.lang.Class} type initializer.
1338    *
1339    * @param <T> The type of the matched object.
1340    * @return A matcher that only matches method descriptions that represent the type initializer.
1341    */
 
1342  1632 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isTypeInitializer() {
1343  1632 return new MethodSortMatcher<T>(MethodSortMatcher.Sort.TYPE_INITIALIZER);
1344    }
1345   
1346    /**
1347    * Matches any method that is virtual, i.e. non-constructors that are non-static and non-private.
1348    *
1349    * @param <T> The type of the matched object.
1350    * @return A matcher for virtual methods.
1351    */
 
1352  4409 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isVirtual() {
1353  4409 return new MethodSortMatcher<T>(MethodSortMatcher.Sort.VIRTUAL);
1354    }
1355   
1356    /**
1357    * Only matches Java 8 default methods.
1358    *
1359    * @param <T> The type of the matched object.
1360    * @return A matcher that only matches Java 8 default methods.
1361    */
 
1362  2 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isDefaultMethod() {
1363  2 return new MethodSortMatcher<T>(MethodSortMatcher.Sort.DEFAULT_METHOD);
1364    }
1365   
1366    /**
1367    * Matches a default constructor, i.e. a constructor without arguments.
1368    *
1369    * @param <T> The type of the matched object.
1370    * @return A matcher that matches a default constructor.
1371    */
 
1372  3 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isDefaultConstructor() {
1373  3 return isConstructor().and(takesArguments(0));
1374    }
1375   
1376    /**
1377    * Only matches the {@link Object#finalize()} method if it was not overridden.
1378    *
1379    * @param <T> The type of the matched object.
1380    * @return A matcher that only matches a non-overridden {@link Object#finalize()} method.
1381    */
 
1382  1438 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isDefaultFinalizer() {
1383  1438 return isFinalizer().and(isDeclaredBy(TypeDescription.OBJECT));
1384    }
1385   
1386    /**
1387    * Only matches the {@link Object#finalize()} method, even if it was overridden.
1388    *
1389    * @param <T> The type of the matched object.
1390    * @return A matcher that only matches the {@link Object#finalize()} method.
1391    */
 
1392  1463 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isFinalizer() {
1393  1463 return named("finalize").and(takesArguments(0)).and(returns(TypeDescription.VOID));
1394    }
1395   
1396    /**
1397    * Only matches the {@link Object#toString()} method, also if it was overridden.
1398    *
1399    * @param <T> The type of the matched object.
1400    * @return A matcher that only matches the {@link Object#toString()} method.
1401    */
 
1402  3 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isHashCode() {
1403  3 return named("hashCode").and(takesArguments(0)).and(returns(int.class));
1404    }
1405   
1406    /**
1407    * Only matches the {@link Object#equals(Object)} method, also if it was overridden.
1408    *
1409    * @param <T> The type of the matched object.
1410    * @return A matcher that only matches the {@link Object#equals(Object)} method.
1411    */
 
1412  3 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isEquals() {
1413  3 return named("equals").and(takesArguments(TypeDescription.OBJECT)).and(returns(boolean.class));
1414    }
1415   
1416    /**
1417    * Only matches the {@link Object#clone()} method, also if it was overridden.
1418    *
1419    * @param <T> The type of the matched object.
1420    * @return A matcher that only matches the {@link Object#clone()} method.
1421    */
 
1422  3 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isClone() {
1423  3 return named("clone").and(takesArguments(0)).and(returns(TypeDescription.OBJECT));
1424    }
1425   
1426    /**
1427    * Only matches the {@link Object#toString()} method, also if it was overridden.
1428    *
1429    * @param <T> The type of the matched object.
1430    * @return A matcher that only matches the {@link Object#toString()} method.
1431    */
 
1432  4 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isToString() {
1433  4 return named("toString").and(takesArguments(0)).and(returns(TypeDescription.STRING));
1434    }
1435   
1436    /**
1437    * Matches any Java bean setter method.
1438    *
1439    * @param <T> The type of the matched object.
1440    * @return A matcher that matches any setter method.
1441    */
 
1442  20 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isSetter() {
1443  20 return nameStartsWith("set").and(takesArguments(1)).and(returns(TypeDescription.VOID));
1444    }
1445   
1446    /**
1447    * Matches any Java bean setter method which takes an argument the given type.
1448    *
1449    * @param type The required setter type.
1450    * @param <T> The type of the matched object.
1451    * @return A matcher that matches any setter method.
1452    */
 
1453  2 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isSetter(Type type) {
1454  2 return isSetter(TypeDefinition.Sort.describe(type));
1455    }
1456   
1457    /**
1458    * Matches any Java bean setter method which takes an argument the given type.
1459    *
1460    * @param type The required setter type.
1461    * @param <T> The type of the matched object.
1462    * @return A matcher that matches a setter method with the specified argument type.
1463    */
 
1464  2 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isSetter(TypeDescription.Generic type) {
1465  2 return isSetter(is(type));
1466    }
1467   
1468    /**
1469    * Matches any Java bean setter method which takes an argument that matches the supplied matcher.
1470    *
1471    * @param matcher A matcher to be allied to a setter method's argument type.
1472    * @param <T> The type of the matched object.
1473    * @return A matcher that matches a setter method with an argument type that matches the supplied matcher.
1474    */
 
1475  2 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isSetter(ElementMatcher<? super TypeDescription.Generic> matcher) {
1476  2 return isSetter().and(takesGenericArguments(new CollectionOneToOneMatcher<TypeDescription.Generic>(Collections.singletonList(matcher))));
1477    }
1478   
1479    /**
1480    * Matches any Java bean getter method.
1481    *
1482    * @param <T> The type of the matched object.
1483    * @return A matcher that matches any getter method.
1484    */
 
1485  17 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isGetter() {
1486  17 return takesArguments(0).and(not(returns(TypeDescription.VOID))).and(nameStartsWith("get")
1487    .or(nameStartsWith("is").and(returnsGeneric(anyOf(boolean.class, Boolean.class)))));
1488    }
1489   
1490    /**
1491    * Matches any Java bean getter method which returns the given type.
1492    *
1493    * @param type The required getter type.
1494    * @param <T> The type of the matched object.
1495    * @return A matcher that matches a getter method with the given type.
1496    */
 
1497  2 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isGetter(Type type) {
1498  2 return isGetter(TypeDefinition.Sort.describe(type));
1499    }
1500   
1501    /**
1502    * Matches any Java bean getter method which returns the given type.
1503    *
1504    * @param type The required getter type.
1505    * @param <T> The type of the matched object.
1506    * @return A matcher that matches a getter method with the given type.
1507    */
 
1508  2 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isGetter(TypeDescription.Generic type) {
1509  2 return isGetter(is(type));
1510    }
1511   
1512    /**
1513    * Matches any Java bean getter method which returns an value with a type matches the supplied matcher.
1514    *
1515    * @param matcher A matcher to be allied to a getter method's argument type.
1516    * @param <T> The type of the matched object.
1517    * @return A matcher that matches a getter method with a return type that matches the supplied matcher.
1518    */
 
1519  2 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> isGetter(ElementMatcher<? super TypeDescription.Generic> matcher) {
1520  2 return isGetter().and(returnsGeneric(matcher));
1521    }
1522   
1523    /**
1524    * Matches a method against its internal name such that constructors and type initializers are matched appropriately.
1525    *
1526    * @param internalName The internal name of the method.
1527    * @param <T> The type of the matched object.
1528    * @return A matcher for a method with the provided internal name.
1529    */
 
1530  44 toggle public static <T extends MethodDescription> ElementMatcher.Junction<T> hasMethodName(String internalName) {
1531  44 if (MethodDescription.CONSTRUCTOR_INTERNAL_NAME.equals(internalName)) {
1532  1 return isConstructor();
1533  43 } else if (MethodDescription.TYPE_INITIALIZER_INTERNAL_NAME.equals(internalName)) {
1534  1 return isTypeInitializer();
1535    } else {
1536  42 return named(internalName);
1537    }
1538    }
1539   
1540    /**
1541    * Matches any type description that is a subtype of the given type.
1542    *
1543    * @param type The type to be checked for being a subtype of the matched type.
1544    * @param <T> The type of the matched object.
1545    * @return A matcher that matches any type description that represents a sub type of the given type.
1546    */
 
1547  31 toggle public static <T extends TypeDescription> ElementMatcher.Junction<T> isSubTypeOf(Class<?> type) {
1548  31 return isSubTypeOf(new TypeDescription.ForLoadedType(type));
1549    }
1550   
1551    /**
1552    * Matches any type description that is a subtype of the given type.
1553    *
1554    * @param type The type to be checked for being a subtype of the matched type.
1555    * @param <T> The type of the matched object.
1556    * @return A matcher that matches any type description that represents a sub type of the given type.
1557    */
 
1558  386 toggle public static <T extends TypeDescription> ElementMatcher.Junction<T> isSubTypeOf(TypeDescription type) {
1559  386 return new SubTypeMatcher<T>(type);
1560    }
1561   
1562    /**
1563    * Matches any type description that is a super type of the given type.
1564    *
1565    * @param type The type to be checked for being a subtype of the matched type.
1566    * @param <T> The type of the matched object.
1567    * @return A matcher that matches any type description that represents a super type of the given type.
1568    */
 
1569  3 toggle public static <T extends TypeDescription> ElementMatcher.Junction<T> isSuperTypeOf(Class<?> type) {
1570  3 return isSuperTypeOf(new TypeDescription.ForLoadedType(type));
1571    }
1572   
1573    /**
1574    * Matches any type description that is a super type of the given type.
1575    *
1576    * @param type The type to be checked for being a subtype of the matched type.
1577    * @param <T> The type of the matched object.
1578    * @return A matcher that matches any type description that represents a super type of the given type.
1579    */
 
1580  7 toggle public static <T extends TypeDescription> ElementMatcher.Junction<T> isSuperTypeOf(TypeDescription type) {
1581  7 return new SuperTypeMatcher<T>(type);
1582    }
1583   
1584    /**
1585    * Matches any type description that declares a super type that matches the provided matcher.
1586    *
1587    * @param matcher The type to be checked for being a super type of the matched type.
1588    * @param <T> The type of the matched object.
1589    * @return A matcher that matches any type description that declares a super type that matches the provided matcher.
1590    */
 
1591  4 toggle public static <T extends TypeDescription> ElementMatcher.Junction<T> hasSuperType(ElementMatcher<? super TypeDescription> matcher) {
1592  4 return hasGenericSuperType(rawType(matcher));
1593    }
1594   
1595    /**
1596    * Matches any type description that declares a super type that matches the provided matcher.
1597    *
1598    * @param matcher The type to be checked for being a super type of the matched type.
1599    * @param <T> The type of the matched object.
1600    * @return A matcher that matches any type description that declares a super type that matches the provided matcher.
1601    */
 
1602  4 toggle public static <T extends TypeDescription> ElementMatcher.Junction<T> hasGenericSuperType(ElementMatcher<? super TypeDescription.Generic> matcher) {
1603  4 return new HasSuperTypeMatcher<T>(matcher);
1604    }
1605   
1606    /**
1607    * Matches any annotations by their type on a type that declared these annotations or inherited them from its
1608    * super classes.
1609    *
1610    * @param type The annotation type to be matched.
1611    * @param <T> The type of the matched object.
1612    * @return A matcher that matches any inherited annotation by their type.
1613    */
 
1614  1 toggle public static <T extends TypeDescription> ElementMatcher.Junction<T> inheritsAnnotation(Class<?> type) {
1615  1 return inheritsAnnotation(new TypeDescription.ForLoadedType(type));
1616    }
1617   
1618    /**
1619    * Matches any annotations by their type on a type that declared these annotations or inherited them from its
1620    * super classes.
1621    *
1622    * @param type The annotation type to be matched.
1623    * @param <T> The type of the matched object.
1624    * @return A matcher that matches any inherited annotation by their type.
1625    */
 
1626  1 toggle public static <T extends TypeDescription> ElementMatcher.Junction<T> inheritsAnnotation(TypeDescription type) {
1627  1 return inheritsAnnotation(is(type));
1628    }
1629   
1630    /**
1631    * Matches any annotations by a given matcher on a type that declared these annotations or inherited them from its
1632    * super classes.
1633    *
1634    * @param matcher A matcher to apply onto the inherited annotations.
1635    * @param <T> The type of the matched object.
1636    * @return A matcher that matches any inherited annotation by a given matcher.
1637    */
 
1638  1 toggle public static <T extends TypeDescription> ElementMatcher.Junction<T> inheritsAnnotation(ElementMatcher<? super TypeDescription> matcher) {
1639  1 return hasAnnotation(annotationType(matcher));
1640    }
1641   
1642    /**
1643    * Matches a list of annotations by a given matcher on a type that declared these annotations or inherited them
1644    * from its super classes.
1645    *
1646    * @param matcher A matcher to apply onto a list of inherited annotations.
1647    * @param <T> The type of the matched object.
1648    * @return A matcher that matches a list of inherited annotation by a given matcher.
1649    */
 
1650  1 toggle public static <T extends TypeDescription> ElementMatcher.Junction<T> hasAnnotation(ElementMatcher<? super AnnotationDescription> matcher) {
1651  1 return new InheritedAnnotationMatcher<T>(new CollectionItemMatcher<AnnotationDescription>(matcher));
1652    }
1653   
1654    /**
1655    * Matches a type by a another matcher that is applied on any of its declared fields.
1656    *
1657    * @param matcher The matcher that is applied onto each declared field.
1658    * @param <T> The type of the matched object.
1659    * @return A matcher that matches any type where another matcher is matched positively on at least on declared field.
1660    */
 
1661  2 toggle public static <T extends TypeDefinition> ElementMatcher.Junction<T> declaresField(ElementMatcher<? super FieldDescription> matcher) {
1662  2 return new DeclaringFieldMatcher<T>(new CollectionItemMatcher<FieldDescription>(matcher));
1663    }
1664   
1665    /**
1666    * Matches a type by a another matcher that is applied on any of its declared methods.
1667    *
1668    * @param matcher The matcher that is applied onto each declared method.
1669    * @param <T> The type of the matched object.
1670    * @return A matcher that matches any type where another matcher is matched positively on at least on declared methods.
1671    */
 
1672  2 toggle public static <T extends TypeDefinition> ElementMatcher.Junction<T> declaresMethod(ElementMatcher<? super MethodDescription> matcher) {
1673  2 return new DeclaringMethodMatcher<T>(new CollectionItemMatcher<MethodDescription>(matcher));
1674    }
1675   
1676    /**
1677    * Matches generic type descriptions of the given sort.
1678    *
1679    * @param sort The generic type sort to match.
1680    * @param <T> The type of the matched object.
1681    * @return A matcher that matches generic types of the given sort.
1682    */
 
1683  3310 toggle public static <T extends TypeDefinition> ElementMatcher.Junction<T> ofSort(TypeDefinition.Sort sort) {
1684  3310 return ofSort(is(sort));
1685    }
1686   
1687    /**
1688    * Matches generic type descriptions of the given sort.
1689    *
1690    * @param matcher A matcher for a generic type's sort.
1691    * @param <T> The type of the matched object.
1692    * @return A matcher that matches generic types of the given sort.
1693    */
 
1694  3310 toggle public static <T extends TypeDefinition> ElementMatcher.Junction<T> ofSort(ElementMatcher<? super TypeDefinition.Sort> matcher) {
1695  3310 return new TypeSortMatcher<T>(matcher);
1696    }
1697   
1698    /**
1699    * Matches a field's generic type against the provided matcher.
1700    *
1701    * @param fieldType The field type to match.
1702    * @param <T> The type of the matched object.
1703    * @return A matcher matching the provided field type.
1704    */
 
1705  2 toggle public static <T extends FieldDescription> ElementMatcher.Junction<T> genericFieldType(Type fieldType) {
1706  2 return genericFieldType(TypeDefinition.Sort.describe(fieldType));
1707    }
1708   
1709    /**
1710    * Matches a field's generic type against the provided matcher.
1711    *
1712    * @param fieldType The field type to match.
1713    * @param <T> The type of the matched object.
1714    * @return A matcher matching the provided field type.
1715    */
 
1716  2 toggle public static <T extends FieldDescription> ElementMatcher.Junction<T> genericFieldType(TypeDescription.Generic fieldType) {
1717  2 return genericFieldType(is(fieldType));
1718    }
1719   
1720    /**
1721    * Matches a field's generic type against the provided matcher.
1722    *
1723    * @param matcher The matcher to apply to the field's type.
1724    * @param <T> The type of the matched object.
1725    * @return A matcher matching the provided field type.
1726    */
 
1727  9 toggle public static <T extends FieldDescription> ElementMatcher.Junction<T> genericFieldType(ElementMatcher<? super TypeDescription.Generic> matcher) {
1728  9 return new FieldTypeMatcher<T>(matcher);
1729    }
1730   
1731    /**
1732    * Matches a field's raw type against the provided matcher.
1733    *
1734    * @param fieldType The field type to match.
1735    * @param <T> The type of the matched object.
1736    * @return A matcher matching the provided field type.
1737    */
 
1738  3 toggle public static <T extends FieldDescription> ElementMatcher.Junction<T> fieldType(Class<?> fieldType) {
1739  3 return fieldType(new TypeDescription.ForLoadedType(fieldType));
1740    }
1741   
1742    /**
1743    * Matches a field's raw type against the provided matcher.
1744    *
1745    * @param fieldType The field type to match.
1746    * @param <T> The type of the matched object.
1747    * @return A matcher matching the provided field type.
1748    */
 
1749  7 toggle public static <T extends FieldDescription> ElementMatcher.Junction<T> fieldType(TypeDescription fieldType) {
1750  7 return fieldType(is(fieldType));
1751    }
1752   
1753    /**
1754    * Matches a field's raw type against the provided matcher.
1755    *
1756    * @param matcher The matcher to apply to the field's type.
1757    * @param <T> The type of the matched object.
1758    * @return A matcher matching the provided field type.
1759    */
 
1760  7 toggle public static <T extends FieldDescription> ElementMatcher.Junction<T> fieldType(ElementMatcher<? super TypeDescription> matcher) {
1761  7 return genericFieldType(rawType(matcher));
1762    }
1763   
1764    /**
1765    * Matches if an annotation is of a given type.
1766    *
1767    * @param type The expected annotation type.
1768    * @param <T> The type of the matched object.
1769    * @return A matcher that matches the annotation's type for being equal to the given type.
1770    */
 
1771  3 toggle public static <T extends AnnotationDescription> ElementMatcher.Junction<T> annotationType(Class<? extends Annotation> type) {
1772  3 return annotationType(new TypeDescription.ForLoadedType(type));
1773    }
1774   
1775    /**
1776    * Matches if an annotation is of a given type.
1777    *
1778    * @param type The expected annotation type.
1779    * @param <T> The type of the matched object.
1780    * @return A matcher that matches the annotation's type for being equal to the given type.
1781    */
 
1782  3 toggle public static <T extends AnnotationDescription> ElementMatcher.Junction<T> annotationType(TypeDescription type) {
1783  3 return annotationType(is(type));
1784    }
1785   
1786    /**
1787    * Matches if an annotation's type matches the supplied matcher.
1788    *
1789    * @param matcher The matcher to match the annotation's type against.
1790    * @param <T> The type of the matched object.
1791    * @return A matcher that matches the annotation's type.
1792    */
 
1793  64 toggle public static <T extends AnnotationDescription> ElementMatcher.Junction<T> annotationType(ElementMatcher<? super TypeDescription> matcher) {
1794  64 return new AnnotationTypeMatcher<T>(matcher);
1795    }
1796   
1797    /**
1798    * Matches exactly the bootstrap {@link java.lang.ClassLoader} . The returned matcher is a synonym to
1799    * a matcher matching {@code null}.
1800    *
1801    * @param <T> The type of the matched object.
1802    * @return A matcher that only matches the bootstrap class loader.
1803    */
 
1804  162 toggle public static <T extends ClassLoader> ElementMatcher.Junction<T> isBootstrapClassLoader() {
1805  162 return new NullMatcher<T>();
1806    }
1807   
1808    /**
1809    * Matches exactly the system {@link java.lang.ClassLoader}. The returned matcher is a synonym to
1810    * a matcher matching {@code ClassLoader.gerSystemClassLoader()}.
1811    *
1812    * @param <T> The type of the matched object.
1813    * @return A matcher that only matches the system class loader.
1814    */
 
1815  4 toggle public static <T extends ClassLoader> ElementMatcher.Junction<T> isSystemClassLoader() {
1816  4 return new EqualityMatcher<T>(ClassLoader.getSystemClassLoader());
1817    }
1818   
1819    /**
1820    * Matches exactly the extension {@link java.lang.ClassLoader}. The returned matcher is a synonym to
1821    * a matcher matching {@code ClassLoader.gerSystemClassLoader().getParent()}.
1822    *
1823    * @param <T> The type of the matched object.
1824    * @return A matcher that only matches the extension class loader.
1825    */
 
1826  4 toggle public static <T extends ClassLoader> ElementMatcher.Junction<T> isExtensionClassLoader() {
1827  4 return new EqualityMatcher<T>(ClassLoader.getSystemClassLoader().getParent());
1828    }
1829   
1830    /**
1831    * Matches any class loader that is either the given class loader or a child of the given class loader.
1832    *
1833    * @param classLoader The class loader of which child class loaders are matched.
1834    * @param <T> The type of the matched object.
1835    * @return A matcher that matches the given class loader and any class loader that is a child of the given
1836    * class loader.
1837    */
 
1838  4 toggle public static <T extends ClassLoader> ElementMatcher.Junction<T> isChildOf(ClassLoader classLoader) {
1839  4 return classLoader == BOOTSTRAP_CLASSLOADER
1840    ? new BooleanMatcher<T>(true)
1841    : ElementMatchers.<T>hasChild(is(classLoader));
1842    }
1843   
1844    /**
1845    * Matches all class loaders in the hierarchy of the matched class loader against a given matcher.
1846    *
1847    * @param matcher The matcher to apply to all class loaders in the hierarchy of the matched class loader.
1848    * @param <T> The type of the matched object.
1849    * @return A matcher that matches all class loaders in the hierarchy of the matched class loader.
1850    */
 
1851  3 toggle public static <T extends ClassLoader> ElementMatcher.Junction<T> hasChild(ElementMatcher<? super ClassLoader> matcher) {
1852  3 return new ClassLoaderHierarchyMatcher<T>(matcher);
1853    }
1854   
1855    /**
1856    * Matches any class loader that is either the given class loader or a parent of the given class loader.
1857    *
1858    * @param classLoader The class loader of which parent class loaders are matched.
1859    * @param <T> The type of the matched object.
1860    * @return A matcher that matches the given class loader and any class loader that is a parent of the given
1861    * class loader.
1862    */
 
1863  5 toggle public static <T extends ClassLoader> ElementMatcher.Junction<T> isParentOf(ClassLoader classLoader) {
1864  5 return classLoader == BOOTSTRAP_CLASSLOADER
1865    ? ElementMatchers.<T>isBootstrapClassLoader()
1866    : new ClassLoaderParentMatcher<T>(classLoader);
1867    }
1868   
1869    /**
1870    * Matches a module if it exists, i.e. not {@code null}.
1871    *
1872    * @param <T> The type of the matched object.
1873    * @return A matcher that validates a module's existence.
1874    */
 
1875  252 toggle public static <T extends JavaModule> ElementMatcher.Junction<T> supportsModules() {
1876  252 return not(new NullMatcher<T>());
1877    }
1878    }